<?php

class Marketing_DocumentController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function preDispatch() {
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {
            $this->_redirect('/user/login');
        }

        $view = new Zend_View();
        $view->headTitle(' > Marketing > Files');
        $this->view->userDetail = $auth->getIdentity();
    }
    public function downloadAction() {

        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        $documentName = $this->_request->getParam('id');
       
        // Now make sure the file actually exists
        if (!file_exists("./uploads/files/$documentName")) {
            echo("File does not exist");
            exit;
        }

        header("Content-disposition: attachment; filename=$documentName");
        header("Content-type: application/octet-stream");
        readfile("./uploads/files/$documentName");        
        exit(0);
    }

}